@extends('template.adminpage')
@section('content')
 
<ol class="breadcrumb">
  <li class="active">Daftar account</li>
</ol>

<div class="container-black">
    <br>
    <p><a data-toggle="modal" data-target="#tambahadmin"><button class="btn btn-sm btn-dark" style="height:30px" ><span class="fa fa-plus"></span> Tambah</button></a></p>
     <div class="table-responsive">
  	 <table class="table table-bordered table-hover">
      <thead>
        <tr>
          <th>No</th>
          <th>Nama admin</th>
          <th>Username</th>
          <th>Role</th>
          <th>Aksi</th>
        </tr>
      </thead>
      <tbody>
        <tr>
        <?php  
        $limit = 10;
        if(Input::get('page')==0 OR Input::get('page')==1){ 
         $no = 1;
        }
        else{
        $no = ((Input::get('page')-1)*$limit)+1;
        }
       ?>
       @foreach($account as $acc)
          <td style="width:10px">{{$no}}</td>
          <td>{{$acc->admin_name}}</td>
          <td>{{$acc->username}}</td>
          <td>{{$acc->admin_group_name}}</td>

          <td style="width:180px"> <a data-toggle="modal" data-target="#ubahdataadmin{{$acc->id}}" title="Ubah Data Admin"><button class="btn btn-xs btn-dark"><span class="fa fa-edit"></span> Edit</button></a> <a data-toggle="modal" data-target="#log{{$acc->id}}" title="Admin log"><button class="btn btn-xs btn-dark"><span class="fa fa-edit"></span> Log</button></a> <a href="{{URL::to('/admin/deleteadmin/'.$acc->id)}}"><button onclick="return confirm('Anda akan menghapus data admin ini?')" class="btn btn-xs btn-dark"><span class="fa fa-edit"></span> Delete</button></a></td>
        <?php $no++; ?>
      </tr>
      @endforeach
      </tbody>


    </table>
  <div class="text-right"><?php echo $account->links(); ?></div>
  </div>
       <div class="modal fade" id="tambahadmin" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:25px">Tambah admin</label></h4>
                    </div>
                    <div align="left">
                              {{Form::open(array(
                                    'url' => '/admin/tambahadmin/',
                                    'method' => 'POST'
                                  ))}}
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Role <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <select type="text" name="admin_admin_group_id" class="form-control" style="width:200px;height:30px" required />
                                        <option value="">Silahkan pilih</option>
                                        <option value="1">Administrator</option>
                                        <option value="0">Superuser</option>
                                    </select>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nama admin <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text" placeholder="Masukan nama admin" name="admin_name" class="form-control" style="width:200px;height:30px" required /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Username<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text" placeholder="Masukan username" name="username" class="form-control" style="width:200px;height:30px" pattern=".{5,}" title="Minmimum 5 letters or numbers." required  /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Password<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="password" placeholder="Masukan password" name="password" class="form-control" style="width:200px;height:30px" pattern=".{5,}" title="Minmimum 5 letters or numbers." required /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Ulangi password<font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="password" placeholder="Masukan password lagi" name="password_confirmation" class="form-control" style="width:200px;height:30px" pattern=".{5,}" title="Minmimum 5 letters or numbers." required  /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5 col-lg-offset-5">
                                 <font color="red">* Data tidak boleh kosong</font><br>
                                  </div>
                                  </div>


                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">
                    <button type="submit" class="btn btn-sm btn-dark"><span class="fa fa-floppy-o"></span> Simpan</button>{{Form::close()}} <button class="btn btn-sm btn-dark" style="margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>

     @foreach($account as $acc)
      <div class="modal fade" id="ubahdataadmin{{$acc->id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:25px">Edit data admin</label></h4>
                    </div>
                    <div align="left">
                              {{Form::open(array(
                                    'url' => '/admin/editadmin/'.$acc->id,
                                    'method' => 'POST'
                                  ))}}
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Role <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <select type="text" name="admin_admin_group_id" class="form-control" style="width:200px;height:30px" required />
                                      <?php
                                      foreach($role as $roles => $val){
                                       if($acc->admin_admin_group_id==$roles){
                                      echo '<option value="'.$roles.'" selected>'.$val.'</option>';
                                      }else{
                                      echo '<option value="'.$roles.'">'.$val.'</option>';

                                      }
                                      }
                                     ?>
                                    </select>
                                  </div>
                                  </div>
                                  <br>

                                   <div class="row">
                                  <div class="col-lg-5">
                                  <label>Nama admin <font color="red">*</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text" placeholder="Masukan nama admin" name="admin_name" class="form-control" style="width:200px;height:30px" value="{{$acc->admin_name}}" required /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Username<font color="red"></font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="text" placeholder="Masukan username" name="username" class="form-control" style="width:200px;height:30px" value="{{$acc->username}}" disabled  /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Password<font color="red">**</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="password" placeholder="Masukan password" name="password" class="form-control" style="width:200px;height:30px"/></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-5">
                                  <label>Ulangi password<font color="red">**</font></label>
                                  </div>
                                  <div class="col-lg-5">
                                    <input type="password" placeholder="Masukan password lagi" name="password_confirmation" class="form-control" style="width:200px;height:30px" /></input>
                                  </div>
                                  </div>
                                  <br>

                                  <div class="row">
                                  <div class="col-lg-6 col-lg-offset-5">
                                 <font color="red">* Data tidak boleh kosong</font><br>
                                 <font color="red">** Kosongkan jika tidak diganti</font><br>
                                  </div>
                                  </div>

                              </div> 
                              </div>   
                    
                    </div>
                    <div class="modal-footer">
                    <button type="submit" class="btn btn-sm btn-dark"><span class="fa fa-floppy-o"></span> Simpan</button>{{Form::close()}} <button class="btn btn-sm btn-dark" style="margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button>
                         
                    </div>
                  </div>
                </div>
              </div>

               
               <?php
                $logadmin = DB::table('sys_admin_log')
                    ->where('admin_log_admin_id',$acc->id)
                    ->orderby('admin_log_date','DESC')
                    ->get();
               ?>
              <div class="modal fade" id="log{{$acc->id}}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="false">
                <div class="modal-dialog modal-lg">
                  <div class="modal-content">
                    <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
 
                    <h4 align="center" class="modal-title"> <label style="margin-top:5px; margin-bottom:25px">Log Admin</label></h4>
                    </div>
                    <div align="left">
                             
                              <div class="row" style="margin-top:10px">
                              <div class="col-md-10 col-md-offset-1">
                              <div style="height:300px;overflow:auto;">
                               <table class="table table-bordered table-hover">
                                <thead>
                                  <tr>
                                    <th>No</th>
                                    <th>Tanggal</th>
                                    <th>Activity</th>
                                  </tr>
                                </thead>
                                <tbody>
                                <?php 
                                    $no=1; 
                                    $totalfinished = 0;
                                ?>
                                @foreach($logadmin as $log)
                                    <td>{{$no}}</td>
                                    <td>{{date("d-M-Y h:i",strtotime($log->admin_log_date))}}</td>
                                    <td>{{$log->admin_log_activity}}</td>
                                </tbody>
                                <?php $no++; ?>
                                @endforeach
                              </table>



                              </div> 
                              </div> 
                              </div>    
                    
                    </div>
                    <div class="modal-footer">

                   <button class="btn btn-sm btn-dark" style="margin-right:5px" class="close" data-dismiss="modal"><span class="fa fa-times"></span> Batal</button></a>
                         
                    </div>
                  </div>
                </div>
              </div>
              @endforeach

</div>


@stop
@stop